/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.exception;

import java.io.FileNotFoundException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;

import cn.qidisoft.edu.hzjt.constants.OpsErrorCode;


/**
 * RPC调用异常处理
 * 
 * @author huanghui951
 * @version $Id: RPCExceptionHandler.java, v 0.1 2016年3月29日 下午7:51:50 huanghui951 Exp $
 */
public class RPCExceptionHandler {

  private RPCExceptionHandler() {

  }

  /**
   * RPC异常包装
   * 
   * @param e
   * @throws RPCException
   */
  public static void rpcExceptionHandle(Exception e) throws RPCException {
    if (e instanceof FileNotFoundException) {
      throw new RPCException(OpsErrorCode.OPS_030001.getCode(), OpsErrorCode.OPS_030001.getMsg(),
          e);
    } else if (e instanceof ConnectException) {
      throw new RPCException(OpsErrorCode.OPS_030002.getCode(), OpsErrorCode.OPS_030002.getMsg(),
          e);
    } else if (e instanceof SocketTimeoutException) {
      throw new RPCException(OpsErrorCode.OPS_030005.getCode(), OpsErrorCode.OPS_030005.getMsg(),
          e);
    }
    throw new RPCException(OpsErrorCode.OPS_030006.getCode(), OpsErrorCode.OPS_030006.getMsg(), e);
  }
}
